package jerry.html.data.convertors;

import java.util.List;

import jerry.html.data.Game;
import jerry.html.events.EvtCap;
import jerry.html.events.GameEndEvtCapImpl;
import jerry.html.events.GameEvtCapImpl;
import jerry.html.events.GameStartEvtCapImpl;
import jerry.html.events.InfoEvtCapImpl;
import jerry.html.events.MapEvtCapImpl;

/**
 * 
 * Used to convert game data
 * 
 * 
 * @author (h0t@_G0|i
 * 
 */
public class GameDataConvertor extends DataConvertor{

	@SuppressWarnings("unchecked")
	@Override
	public boolean convertData(List<? extends EvtCap> eventData) {
		boolean flag = false;
		Game g = getGame();
		if(dataType.equals(GameEvtCapImpl.class)){
			for (GameEvtCapImpl evtCap : (List<GameEvtCapImpl>)eventData) {
				g.getGameDetails().put(evtCap.param, evtCap.value + evtCap.value2);
			}
			flag = true;
		}
		if(dataType.equals(InfoEvtCapImpl.class)){
			for (InfoEvtCapImpl evtCap : (List<InfoEvtCapImpl>)eventData) {
				g.getGameDetails().put(evtCap.infoType, evtCap.infoDetail.toString());
				if(evtCap.infoType.equals("Absolute_Time")) {
					g.setIdentity(evtCap.infoDetail.get(0));
				}
			}
			flag = true;
		}
		if(dataType.equals(MapEvtCapImpl.class)){
			for (MapEvtCapImpl evtCap : (List<MapEvtCapImpl>)eventData) {
				g.getGameDetails().put(evtCap.param, evtCap.value);
			}
			flag = true;
		}
		if(dataType.equals(GameStartEvtCapImpl.class)) {
			g.setTotalTime(g.getTotalTime()-eventData.get(0).getTimeStamp());
			flag = true;
		}
		if(dataType.equals(GameEndEvtCapImpl.class)) {
			GameEndEvtCapImpl evtCap = (GameEndEvtCapImpl) eventData.get(0);
			g.setTotalTime(evtCap.getTimeStamp() + g.getTotalTime());
			g.setGameEndString(evtCap.reason + " " + evtCap.endedBy);
			flag = true;
		}
		return flag;
	}

}
